package com.fhz.core_lib.dao.database;

import android.app.Application;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.databinding.adapters.Converters;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;
import androidx.sqlite.db.SupportSQLiteDatabase;

import com.fhz.core_lib.dao.UserDao;
import com.fhz.core_lib.entity.LoggedInUser;

/**
 * 时间:2021/11/25
 *
 * @author msfeng
 * 简述: database
 */
@Database(entities = {LoggedInUser.class}, version = 1,exportSchema = false)
@TypeConverters({MyConverters.class})
public abstract class UserDatabase extends RoomDatabase {

    public static final String DB_NAME = "UserDataBase.db";

    public abstract UserDao userDao();
    private static volatile UserDatabase instance;

    public static synchronized UserDatabase getInstance(Context context){
        if (instance == null){
            instance = createDatabase(context);
        }
        return instance;
    }

    private static UserDatabase createDatabase(Context context) {
        return Room.databaseBuilder(context,UserDatabase.class,DB_NAME)
                .allowMainThreadQueries().build();
    }
}
